<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>卡片名称</span>
      </div>
      <!-- from查询表单 -->
      <el-form :inline="true" :model="fromlist" class="demo-form-inline">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="订单编号">
              <el-input
                v-model="fromlist.orderSn"
                placeholder="订单编号"
                size="mini"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单状态">
              <el-select
                size="mini"
                v-model="fromlist.status"
                placeholder="请选择"
              >
                <el-option label="待处理" :value="0"></el-option>
                <el-option label="退货中" :value="1"></el-option>
                <el-option label="已完成" :value="2"></el-option>
                <el-option label="已拒绝" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4" :offset="20">
            <el-form-item>
              <el-button type="primary" @click="resetForm" size="mini"
                >重置</el-button
              >
              <el-button type="primary" @click="onSubmit" size="mini"
                >查询</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- 订单列表 -->
    <el-card class="box-card">
      <el-table :data="list" border style="width: 100%">
        <el-table-column type="index" align="center" fixed width="50">
        </el-table-column>
        <el-table-column
          prop="orderSn"
          label="订单编号"
          align="center"
          width="240"
        >
        </el-table-column>
        <el-table-column
          prop="status"
          label="退单状态"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            <div
              style="
                width: 80px;
                margin: 0 auto;
                padding: 10px;
                background-color: #f56c6c;
                color: #fff;
              "
              v-if="scope.row.status === 0"
            >
              待处理
            </div>
            <div
              style="
                width: 80px;
                margin: 0 auto;
                padding: 10px;
                background-color: #f56c6c;
                color: #fff;
              "
              v-else-if="scope.row.status === 1"
            >
              退货中
            </div>
            <div
              style="
                width: 80px;
                margin: 0 auto;
                padding: 10px;
                background-color: #f56c6c;
                color: #fff;
              "
              v-else-if="scope.row.status === 2"
            >
              已完成
            </div>
            <div
              style="
                width: 80px;
                margin: 0 auto;
                padding: 10px;
                background-color: #f56c6c;
                color: #fff;
              "
              v-else-if="scope.row.status === 3"
            >
              已拒绝
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="description"
          align="center"
          label="描述"
          width="150"
        >
        </el-table-column>
        <el-table-column
          prop="reason"
          label="退单原因"
          align="center"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="productName"
          label="商品名称"
          align="center"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="productAttr"
          label="商品属性"
          align="center"
          width="220"
        >
        </el-table-column>
        <el-table-column
          prop="handleNote"
          label="商家备注"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="添加时间"
          align="center"
          width="200"
        >
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row)"
              type="primary"
              size="small"
              icon="el-icon-view"
              >查看订单</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="last.start"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="last.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script >
import { findReturnApply } from "@/api/order/index";

export default {
  data() {
    return {
      total: 0,
      last: {
        start: 1,
        limit: 10,
      },
      list: [],
      fromlist: {
        orderSn: "",
        status: "",
      },
    };
  },
  created() {
    this.findReturnApplyAPI();
  },
  components: {},

  computed: {},

  mounted() {},

  methods: {
    // 分页查询
    handleSizeChange(val) {
      var _this = this
      this.last.limit = val
      this.findReturnApplyAPI()
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      var _this = this

      this.last.start = val
      this.findReturnApplyAPI()
      console.log(`当前页: ${val}`)
    },
    // 查看订单
    handleClick(row) {
      this.$router.push({path:"/order/delorderlist",query:{id:row.id,orderId:row.orderId}})
    },
    // 重置
    resetForm() {
      this.$data.fromlist = this.$options.data().fromlist;
    },
    // 查询
    onSubmit() {
      console.log(this.fromlist);
       var _this = this;
      this.$data.last = this.$options.data().last;
      findReturnApply(this.last.start, this.last.limit,this.fromlist).then(res=>{
        if (res.success) {
          _this.total = res.data.total;
          _this.list = res.data.rows;
        }else{
          _this.$success.console.error("请输入正确信息");
        }
      })
    },
    findReturnApplyAPI() {
      var _this = this;
      findReturnApply(this.last.start, this.last.limit).then((res) => {
        console.log(res.data.rows);
        if (res.success) {
          // res.data.rows.productAttr=JSON.parse(res.data.rows.productAttr)
          _this.total = res.data.total;
          _this.list = res.data.rows;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.box-card {
  margin: 30px;
}
</style>